Global Events

void OnSimulationStart();

This event is invoked when the simulation starts. It can be used to subscribe to events or initialize property values.

 

Note that for large projects or projects that include a number of device connections, there may be a considerable delay in establishing the connections. When the OnSimulationStart function is called the devices may not have connected and any MoveProduct command may be compromised. To work around this, the code in the OnSimulationStart function call can be called after a delay (e.g. 5 seconds after starting)

function OnSimulationStart() {
  LogDebug("OnSimulationStart called");
  SetTimerEx(1024,5000,"OnSimulationRealStart",null);
}

...

function OnSimulationRealStart() {
  LogDebug("OnSimulationRealStart called");
  ...
}

void OnSimulationStop();

This event is invoked when the simulation stops. It can be used to free any resources previously allocated, events are automatically unsubscribed when the simulation stops.

 

void OnSimulationStopping();

New from Sym3 V5.2. This function is called as soon as the Stop current simulation button is pressed.

New projects will automatically create this function but this function will need to be manually added to the scripting from older projects if this feature is required. The default function is;

			
function OnSimulationStopping()  {
  LogDebug("OnSimulationStopping called");
  DeleteAllProducts();
}
 

When the Simulation stops, by default all products will be automatically deleted. Placing the call DeleteAllProducts in this function ensures that the products are removed early to ensure the state of PEs are changed to unblocked and updated to any PLCs before these connections are closed.

 

void PauseSimulation();

New in Sym3 V5.2. Call this function when the script needs to Pause the simulation e.g. when a pending issue is detected in the script the Simulation can be paused to trap this. The Pause button will change to Resume as it does on a manual pause.

Note that, once paused, the simulation can only be un-paused manually or with a Macro as all timers and events in the Simulation are also paused.

 

void ResumeSimulation();

New in v7.6. Call this function to resume the simulation after being paused.

Once paused, the simulation can be resumed manually or by calling this function from a macro:

Example: A menu can call a simulation script function:

Project.CallSimulationScriptFunction("Resume", Caller, 0);

And in simulation script:

function Resume() {
    ResumeFunction();
}